import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'

import Index from './views/index.vue'
import Dashboard from './views/dashboard'
import MenuConfig from './views/menu'
import RoleConfig from './views/role'
import Event from './views/event'
import EventInfo from './views/eventInfo'

import InterfaceList from './views/config/interfaceList'


Vue.use(Router)

let r = new Router({
    routes: [
        {
            path: '/',
            name: 'index',
            component: Index,
            children : [
                {
                    name : 'dashboard',
                    path: '/dashboard',
                    component: Dashboard,
                    meta: {
                        title:"首页",
                    }
                },
                {
                    name : 'menuconfig',
                    path: '/menuconfig',
                    component: MenuConfig,
                    meta: {
                        title:"设置菜单",
                    }
                },
                {
                    name : 'roleconfig',
                    path: '/roleconfig',
                    component: RoleConfig,
                    meta: {
                        title:"设置角色",
                    }
                },

                {
                    path: '/interfacelist.html',
                    name: 'synclist',
                    component: InterfaceList,
                    meta: {
                        title:"同步接口",
                    }
                },

                {
                    path: '/event.html',
                    name: 'event',
                    component: Event,
                    meta: {
                        title:"事件列表",
                    }
                },

                {
                    path: '/eventinfo.html',
                    name: 'eventinfo',
                    component: EventInfo,
                    meta: {
                        title:"事件详情",
                    }
                },
            ]
        },
        
        {
            path: '/login',
            name: 'login',
            component: () => import('./views/login/index.vue')
        },
    ],

    scrollBehavior (to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { x: 0, y: 0 }
        }
    },
})


r.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
});


export default r;
